package com.kevinwu.zookeepertask.taskone.client;

import com.kevinwu.zookeepertask.taskone.service.UserService;

public class RpcConnect extends Thread{

    public String hostName="";
    private int port=0;
    //有参构造函数
    public RpcConnect(String hostName, int port){
        this.hostName = hostName;
        this.port = port;
    }
    /**
     * rpc连接
     */
    public void run() {
        //声明对象
        RpcConsumer rpcConsumer = new RpcConsumer();
        //创建代理对象
        UserService proxy = (UserService) rpcConsumer.createProxy(UserService.class,hostName,port);
        while (true){
            /**
             * 每2秒发哦送一次请求，打印返回结果
             */
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("服务端返回信息："+proxy.sayHello("are you ok?"));
        }
    }
}
